home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Grafik & Text / Fractal Trees / Sources etc / Fractal Trees 2.cpp next >
C/C++ Source or Header  |  1997-02-11  |  2KB  |  152 lines

  1. #include "FractalTreeObject.cpp"
  2.  
  3. #define kBaseResID        128
  4. #define kMoveToFront    (WindowPtr)-1L
  5. #define kFontSize        9
  6. #define kSleep            1L
  7.  
  8.  
  9. // Globals
  10.  
  11. Boolean        gDone;
  12.  
  13.  
  14.  
  15. // ****************************************************************
  16. // Prototypes
  17.  
  18. void ToolBoxInit();
  19. void WindowInit();
  20. void MainLoop();
  21. void EventInit();
  22. void HandleMouseDown( EventRecord *event );
  23.  
  24.  
  25.  
  26. // ****************************************************************
  27. // Main
  28.  
  29. void main()
  30. {
  31.     ToolBoxInit();
  32.     WindowInit();
  33.     
  34.     MainLoop();
  35. }
  36.  
  37.  
  38.  
  39. // ****************************************************************
  40. // ToolBoxInit
  41.  
  42. void ToolBoxInit()
  43. {
  44.     InitGraf( &qd.thePort );
  45.     InitFonts();
  46.     InitWindows();
  47.     InitMenus();
  48.     TEInit();
  49.     InitDialogs( nil );
  50.     InitCursor();
  51. }
  52.  
  53.  
  54.  
  55. // ****************************************************************
  56. // WindowInit
  57.  
  58. void WindowInit()
  59. {
  60.     WindowPtr    window;
  61.     Rect        windRect;
  62.     
  63.     window = GetNewWindow( kBaseResID, nil, kMoveToFront );
  64.     
  65.     if (window == nil)
  66.     {
  67.         SysBeep( 10 ); // couldn't load wind resource
  68.         
  69.         ExitToShell();
  70.     }
  71.  
  72.     SetPort( window );
  73.     TextSize( kFontSize );
  74.     
  75.     ShowWindow( window );
  76. }
  77.  
  78.  
  79.  
  80. // ****************************************************************
  81. // EventInit
  82.  
  83. void EventInit()
  84. {
  85.     OSErr    err;
  86.     long    result;
  87.  
  88.     err = Gestalt(gestaltAppleEventsAttr, &result);
  89. }
  90.  
  91.  
  92. // ****************************************************************
  93. // MainLoop
  94.  
  95. void MainLoop()
  96. {
  97.     EventRecord event;
  98.     int drawDone = 0;
  99.     
  100.     FractalTree Tree1(14, 0.69, 3.1415926/8, 0.3, 0.9);  // tested up to 17 at 20000 K
  101.     
  102.     gDone = false;
  103.     while (gDone == false)
  104.     {
  105.         if (drawDone == 0)
  106.         {
  107.             
  108.             Tree1.GrowTree();
  109.             Tree1.DrawTree();
  110.             drawDone = 1;
  111.         }
  112.         
  113.         WaitNextEvent(everyEvent, &event, kSleep, NULL);    
  114.         
  115.         switch ( event.what )
  116.         {
  117.             case mouseDown:
  118.                 HandleMouseDown( &event );
  119.                 break;
  120.         }
  121.     }
  122. }
  123.  
  124.  
  125.  
  126. // ****************************************************************
  127. // HandleMouseDown
  128.  
  129. void HandleMouseDown( EventRecord *event )
  130. {
  131.     WindowPtr    window;
  132.     short        windowPart;
  133.     
  134.     windowPart = FindWindow( event->where, &window );
  135.     
  136.     switch ( windowPart )
  137.     {
  138.         case inSysWindow:
  139.             SystemClick( event, window );
  140.             break;
  141.         case inDrag:
  142.             DragWindow( window, event->where, &(qd.screenBits.bounds) );
  143.             break;
  144.         case inGoAway:
  145.             gDone = true;
  146.             break;
  147.     }
  148. }
  149.  
  150.  
  151.  
  152.